﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Notes
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            tbx.Focus();
        }

        private void btn_pin_Click(object sender, RoutedEventArgs e)
        {
            this.Topmost = !this.Topmost;
        }

        private void btn_close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

                    // 支持标题栏拖动
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);

            // 获取鼠标相对标题栏位置
            Point position = e.GetPosition(grid);

            // 如果鼠标位置在标题栏内，允许拖动
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (position.Y >= 0 && position.Y < 20)
                {
                    this.DragMove();                    
                }
            }
        }

        private void tbx_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.OemPlus&& Keyboard.IsKeyDown(Key.LeftCtrl))
            {
                tbx.FontSize += 3;
                e.Handled = true;
            }
            if (e.Key == Key.OemMinus && Keyboard.IsKeyDown(Key.LeftCtrl) && tbx.FontSize > 3)
            {
                tbx.FontSize -= 3;
                e.Handled = true;
            }
            
        }

        private void btn_resize_Click(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Normal;
        }

    }
}
